package cn.bugstack.domain.activity.service.discount;

import cn.bugstack.domain.activity.model.valobj.GroupBuyActivityDiscountVO;
import cn.bugstack.types.common.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 满减折算
 */
@Slf4j
@Service("MJ")
public class MJCalculateService extends AbstractDiscountCalculateService{




    @Override
    protected BigDecimal doCalculate(BigDecimal originalPrice, GroupBuyActivityDiscountVO.GroupBuyDisCount groupBuyDisCount) {

        String marketExpr = groupBuyDisCount.getMarketExpr();
        String[] split = marketExpr.split(Constants.SPLIT);
        BigDecimal x = new BigDecimal(split[0]);
        BigDecimal y = new BigDecimal(split[1]);

        if (originalPrice.compareTo(x) < 0){
            //如果原始价格不满足满减
            return originalPrice;
        }
        //满减计算
        BigDecimal deductionPrice = originalPrice.subtract(y);
        if(deductionPrice.compareTo(BigDecimal.ZERO) <= 0){
            return new BigDecimal("0.01");
        }

        return deductionPrice;
    }

    public static void main(String[] args) {
        BigDecimal x = new BigDecimal("100.0");
        BigDecimal y = new BigDecimal("50.0");
        int i = y.compareTo(x);
        System.out.printf("i" + i);
    }



}
